package vm;

import java.lang.reflect.Method;
import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

/**
 * @author zzb
 * @since 2021-01-20
 */
public class JavaMethodAreaOOM {

  public static void main(String[] args) {
    while (true) {
      Enhancer enhancer = new Enhancer();
      enhancer.setSuperclass(OOMObject.class);
      enhancer.setUseCache(false);
      enhancer.setCallback(new MethodInterceptor() {
        @Override
        public Object intercept(Object obj, Method method, Object[] objects, MethodProxy methodProxy)
            throws Throwable {
          return methodProxy.invokeSuper(obj, objects);
        }
      });
      enhancer.create();
    }
  }

  static class OOMObject {

  }
  /**
   * Exception in thread "main"
   * Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "main"
   */
}
